rm(list=ls())
set.seed(1234)
library(car)
library(plyr)
library(ggplot2)
library(psycho)
library(texreg)
library(psych)
library(effectsize)

setwd(".../Data/Raw")

modeldata<-read.csv("AusNorFrance.csv") 

##create treatment number 

modeldata$Vignettes_DO_treat1 <-recode(modeldata$QSAMPLE21, " 1 = 1; else=0")
modeldata$Vignettes_DO_treat2 <-recode(modeldata$QSAMPLE22, " 1 = 2; else=0")
modeldata$Vignettes_DO_treat3 <-recode(modeldata$QSAMPLE23, " 1 = 3; else=0")


modeldata$treat<-modeldata$Vignettes_DO_treat1 +  modeldata$Vignettes_DO_treat2 + modeldata$Vignettes_DO_treat3

table(modeldata$treat)

#remove speedsters, those that compelted our module in under 10 seconds 

modeldata <-subset(modeldata, modeldata $SECT12 > 10) 

#create substantive legitmacy and procedural legitmacy standardized scores 
#Recode values

modeldata[modeldata =="Very unfair"]<-1
modeldata[modeldata =="Unfair"]<-2
modeldata[modeldata =="Somewhat unfair"]<-2
modeldata[modeldata =="Somewhat fair"]<-3
modeldata[modeldata =="Fair"]<-3
modeldata[modeldata =="Very fair"]<-4

modeldata[modeldata =="Strongly disagree"]<-1
modeldata[modeldata =="Disagree"]<-2
modeldata[modeldata =="Agree"]<-3
modeldata[modeldata =="Strongly agree"]<-4
modeldata[modeldata =="Strongly Agree"]<-4

modeldata[modeldata =="Somewhat disagree"]<-2
modeldata[modeldata =="Somewhat agree"]<-3

names(modeldata)[names(modeldata) == "Q13I1_0"] <- "decide_citizen"
names(modeldata)[names(modeldata) == "Q13I1_1"] <- "decide_women"
names(modeldata)[names(modeldata) == "Q13I1I2"] <- "fair_women"
names(modeldata)[names(modeldata) == "Q13I2"] <- "decisionprocess"

##sexual harassment vignettes (treat 1 = AMP, treat 2 = GBP, treat 3 = Q-GBP)

modeldata $decide_citizen<-as.numeric(as.character(modeldata $decide_citizen))
modeldata $decide_women <-as.numeric(as.character(modeldata $decide_women))
modeldata $decisionprocess <-as.numeric(as.character(modeldata $decisionprocess))
modeldata $fair_women <-as.numeric(as.character(modeldata $fair_women))

#create the substantive legitimacy index

factor1<-omega(modeldata[,c(125, 126, 127)], nfactors=1) 
modeldata $SubLeg<-factor1$scores[,1]

#standardizie 
modeldata $SubLegStand<-standardize(modeldata $SubLeg)

#note for these surveys, we had space constraints and could only include one question measuring procedural legitimacy: whether the respondent thought the decision-making process was fair (as noted in the main manuscript).

#standadize
modeldata $ProLegStand<-standardize(modeldata $decisionprocess)

#create and export model dataset 

NorAusFranceAgg<-modeldata[, c(136, 138, 139, 1, 57, 37)] 
write.csv(NorAusFranceAgg, "NorAusFranceAgg.csv")

#Note that these countries did not include vignettes 4 - 6 on animal mistreament as noted in the main manuscript. 

